package com.scs.application.modules.order.excel.handler;/**
 * @Description:
 */

import cn.afterturn.easypoi.handler.impl.ExcelDataHandlerDefaultImpl;
import com.scs.application.core.utils.Reflections;
import com.scs.application.core.utils.SpringHolder;
import com.scs.application.core.utils.StringUtils;
import com.scs.application.core.utils.UserUtils;
import com.scs.application.modules.base.entity.HospitalWarehouse;
import com.scs.application.modules.base.service.HospitalWarehouseService;
import com.scs.application.modules.order.dto.PurchaseOrderDTO;

/**
 * @ClassName HospitalWareHouseDataHandler
 * @Description
 */
public class HospitalWareHouseDataHandler extends ExcelDataHandlerDefaultImpl<PurchaseOrderDTO> {
    public String[] getNeedHandlerFields() {
        return new String[]{"送达地点名称"};
    }

    public Object importHandler(PurchaseOrderDTO obj, String name, Object value) {
        if (!"送达地点名称".equalsIgnoreCase(name)) {
            return null;
        }
        if (value == null || StringUtils.isBlank(value.toString())) {
            return null;
        }
        String warehouseName = value.toString();
        HospitalWarehouseService hospitalWarehouseService = SpringHolder.getBean(HospitalWarehouseService.class);
        String hospitalId = UserUtils.getHospitalId();
        HospitalWarehouse hospitalWarehouse = hospitalWarehouseService.findByWarehouseName(warehouseName, hospitalId);

        if (hospitalWarehouse != null && Reflections.getAccessibleField(obj, "warehouseId") != null) {
            Reflections.setFieldValue(obj, "warehouseId", hospitalWarehouse.getId());
        }
        return null;
    }
}
